package fr.afcepf.ai89.esharing.data;

import java.util.Date;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import fr.afcepf.ai89.esharing.entity.Avis;
import fr.afcepf.ai89.esharing.entity.SousAvis;

@Stateless
public class DAOSousAvis implements IDAOSousAvis {

	@PersistenceContext(unitName = "ESharingPhase22")
	EntityManager em;

	@Override
	public SousAvis getSousAvis(int idSousAvis) {
		
		Query hql = em.createQuery("SELECT sa FROM SousAvis sa WHERE sa.idSousAvis = :param");
		hql.setParameter("param", idSousAvis);
		SousAvis sAv = (SousAvis)hql.getSingleResult();
		
		return sAv;

	}

	@Override
	public List<SousAvis> getSousAvis() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<SousAvis> getSousAvis(Avis avis) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int addSousAvis(SousAvis sousAvis) {
		
		em.persist(sousAvis);
		
		Query hql = em.createQuery("SELECT MAX(idSousAvis) FROM SousAvis sa");
		int idSA = (Integer)hql.getSingleResult();
		
		return idSA;
	}

	@Override
	public int majSousAvis(SousAvis sousAvis) {
		// TODO Auto-generated method stub
		return 0;
	}

}
